@extends('layout.page')
@section('title','奖池 - 列表')


@section('static-page')
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>奖池管理<small></small></h5>
                </div>
                <div class="ibox-content">
                    <div class="">
                        <a href="/ceb/giftPacks/create" class="btn btn-primary ">添加</a>
                    </div>

                    {{--搜索分页代码块--}}
                    <div class="row">
                       {{-- <label class="adha-pro-pagelable">每页显示</label>--}}
                        <form action="" method="get">
                            <div class="col-sm-2 m-b-xs">
                                <div class="input-group">
                                    <input placeholder="开始日期" name="start_time" value="{{$start_time}}" class="form-control layer-date" readonly id="start">
                                </div>
                            </div>
                            <div class="col-sm-2 m-b-xs">
                                <div class="input-group">
                                    <input placeholder="结束日期" readonly name="end_time" value="{{$end_time}}" class="form-control layer-date" id="end">
                                </div>
                            </div>

                            <div class="col-sm-3">
                                <div class="input-group">
                                 {{--   <input name="searchVal" value="@if(!empty($searchVal)){{$searchVal}}@endif"
                                           type="text" placeholder="请输入关键词" class="input-sm form-control"><span class="input-group-btn">
                                            <button type="submit" class="btn btn-sm btn-primary"> 搜索</button></span>--}}
                                    <button type="submit" class="btn btn-sm btn-primary"> 搜索</button>
                                </div>
                            </div>
                        </form>
                    </div>


                    <table class="table table-striped table-bordered table-hover">
                        <thead>
                        <tr>
                            <th>ID</th>
                            <th>奖池名称</th>
                            <th>总金额</th>
                            <th>生效时间</th>
                            <th>失效时间</th>
                            <th>关联活动</th>
                            <th>关联群体</th>
                            <th>已发放</th>
                            <th>已使用</th>
                            <th>总投资</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                            @foreach($array_list as $item )
                                <?php
                                    $array_gift = json_decode($item['items'],true);
                                    $sum = 0;
                                    foreach ($array_gift['red_packet_list'] as $key =>$val) {
                                        $sum += $val['value'];
                                    }
                                    foreach ($array_gift['cash_voucher_list'] as $key =>$val) {
                                        $sum += $val['value'];
                                    }
                                ?>
                            <tr class="gradeA">
                                <td>{{$item['id']}}</td>
                                <td>{{$item['name']}}</td>
                                <td>{{$sum}}</td>
                                <td>{{ date('Y-m-d',$item['start_time']) }}</td>
                                <td>{{ date('Y-m-d',$item['end_time']) }}</td>
                                <td>{{isset($item['activeName'])?$item['activeName']:'-'}}</td>
                                <td>{{isset($item['community'])?$item['community']:'-'}}</td>
                                <td>{{isset($item['owner_count'])?$item['owner_count']:'-'}}</td>
                                <td>{{isset($item['used_count'])?$item['used_count']:'-'}}</td>
                                <td>{{isset($item['investment_amount'])?$item['investment_amount']:'-'}}</td>
                                <td class="center">
                                    @if($item['status'] == $permitEdit)
                                    <a href="/ceb/giftPacks/edit?id={{$item['id']}}">编辑</a>
                                    <a href="/ceb/giftPacks/review?id={{$item['id']}}">|审核|</a>
                                    @endif
                                    <a href="/ceb/giftPacks/details?id={{$item['id']}}">详情</a>
                                </td>
                            </tr>
                            @endforeach
                        </tbody>
                        <tfoot>
                            <tr>
                                <th>ID</th>
                                <th>名称</th>
                                <th>总金额</th>
                                <th>生效时间</th>
                                <th>实效时间</th>
                                <th>关联活动</th>
                                <th>关联群体</th>
                                <th>已发放</th>
                                <th>已使用</th>
                                <th>总投资</th>
                                <th>操作</th>
                            </tr>
                        </tfoot>
                    </table>
                    {{--分页--}}
                    <div>
                        <div class="pull-right">
                            {!! $list->appends(['pageSize'=>$pageSize,'start_time'=>$start_time,'end_time'=>$end_time])->render()  !!}
                        </div>
                    </div>
                </div>
            </div>
        </div>
        @endsection
@section('javascript')
<script>
    $(document).ready(function () {

        $('.delete-product').click(function () {
            var docuElem=$(this);
            var permissionId=docuElem.data('value');
            var title=docuElem.data('title');
            if(window.confirm('你确定删除'+ title+ '？')){
                //继续执行
                $.ajaxSetup({
                    headers: { 'X-CSRF-TOKEN' : '{{ csrf_token() }}' }
                });
                $.ajax({
                    type:'post',
                    url:'{{ url('/admin/permission/delete') }}',
                    dataType:'json',
                    data:{permissionId:permissionId},
                    success: function(data){
                        data=eval(data);
                        if(data.code==200){
                            layer.msg(data.message, {icon: 6});
                            docuElem.parents('.gradeA').remove();
                        }else{
                            layer.msg(data.message, {icon: 5});
                        }
                    }
                });
            }
        });

    });

</script>
@endsection
